package com.itfreer.data.general;

/**
 * 定义数据类型转换类
 */
public class ObjectDataTypeConvert implements IDataTypeConvert {

	public String Convert(GlobalDataType dateType) {
		String typeName = "";
		switch (dateType) {
		case Boolean:
			typeName = "java.lang.Boolean";
			break;
		case Char:
			typeName = "SYSTEM.CHAR";
			break;
		case String:
			typeName = "java.lang.String";
			break;
		case Text:
			typeName = "java.lang.String";
			break;
		case Date:
			typeName = "java.util.Date";
			break;
		case DateTime:
			typeName = "java.util.Date";
			break;
		case Decimal:
			typeName = "java.math.BigDecimal";
			break;
		case Double:
			typeName = "java.lang.Double";
			break;
		case Single:
			typeName = "java.lang.Integer";
			break;
		case Int16:
			typeName = "java.lang.Integer";
			break;
		case Int32:
			typeName = "java.lang.Integer";
			break;
		case Int64:
			typeName = "java.lang.Integer";
			break;
		case UInt16:
			typeName = "java.lang.Integer";
			break;
		case UInt32:
			typeName = "java.lang.Integer";
			break;
		case UInt64:
			typeName = "java.lang.Integer";
			break;
		case ByteArray:
			typeName = "SYSTEM.BINARY";
			break;
		case NoDefault:
			break;
		default:
			break;
		}
		return typeName;

	}

	@Override
	public GlobalDataType Convert(String dateType) {
		GlobalDataType gType = GlobalDataType.NoDefault;
		if (null == dateType || "".equals(dateType)) {
			throw new RuntimeException("数据类型不能为空,请检查字段表。");
		}
		dateType = dateType.toUpperCase();
		if ("JAVA.LANG.BOOLEAN".equals(dateType) || "BOOLEAN".equals(dateType)) {
			gType = GlobalDataType.Boolean;
		} else if ("SYSTEM.CHAR".equals(dateType) || "CHAR".equals(dateType)) {
			gType = GlobalDataType.Char;
		} else if ("JAVA.LANG.STRING".equals(dateType)
				|| "STRING".equals(dateType)) {
			gType = GlobalDataType.String;
		} else if ("JAVA.LANG.STRING".equals(dateType)
				|| "TEXT".equals(dateType)) {
			gType = GlobalDataType.Text;
		} else if ("JAVA.UTIL.DATE".equals(dateType) || "DATE".equals(dateType)) {
			gType = GlobalDataType.Date;
		} else if ("JAVA.LANG.DATETIME".equals(dateType)
				|| "DATETIME".equals(dateType)) {
			gType = GlobalDataType.DateTime;
		} else if ("JAVA.MATH.BIGDECIMAL".equals(dateType)
				|| "BIGDECIMAL".equals(dateType)) {
			gType = GlobalDataType.Decimal;
		} else if ("JAVA.LANG.DOUBLE".equals(dateType)
				|| "DOUBLE".equals(dateType)) {
			gType = GlobalDataType.Double;
		} else if ("INT16".equals(dateType)) {
			gType = GlobalDataType.Int16;
		} else if ("INT32".equals(dateType)) {
			gType = GlobalDataType.Int32;
		} else if ("INT64".equals(dateType)) {
			gType = GlobalDataType.Int64;
		} else if ("BYTE".equals(dateType)) {
			gType = GlobalDataType.ByteArray;
		} else {
			gType = GlobalDataType.NoDefault;
		}
		return gType;
	}
}